// ----------------------------------------
// Filename: Clock.c
// Description: Routines to implement clock
// Author: Anton Jatmiko
// Date: 21 April 2014

#include "Clock.h"

// ----------------------------------------
// Clock_Init
//
// Initialize clock variables
// Input:
//   clkDAY is a pointer to day
//   clkHR is a pointer to hour
//   clkMIN is a pointer to minute
//   clkSEC is a pointer to second
// Output:
//   none
// Conditions:
//   none
void Clock_Init(UINT8 * const clkDAY, UINT8 * const clkHR, UINT8 * const clkMIN, UINT8 * const clkSEC)
{
    *clkDAY = *clkHR = *clkMIN = *clkSEC = 0;
}

// ----------------------------------------
// Clock_Update
//
// Update clock variables
// Input:
//   clkDAY is a pointer to day
//   clkHR is a pointer to hour
//   clkMIN is a pointer to minute
//   clkSEC is a pointer to second
// Output:
//   none
// Conditions:
//   none
void Clock_Update(UINT8 * const clkDAY, UINT8 * const clkHR, UINT8 * const clkMIN, UINT8 * const clkSEC)
{
    ++(*clkSEC);

    if (*clkSEC > 59)
    {
        ++(*clkMIN);
        *clkSEC = 0;
    }

    if (*clkMIN > 59)
    {
        ++(*clkHR);
        *clkMIN = 0;
    }

    if (*clkHR > 23)
    {
        ++(*clkDAY);
        *clkHR = 0;
    }
}